﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//using InControl.Properties;

namespace InControl
{
    public partial class INV_MDIParent : Form
    {
        private int childFormNumber = 0;
        public AppControl appDriver = new AppControl();
     
        public INV_MDIParent()
        {
            InitializeComponent();
        }

        private void ShowNewForm(object sender, EventArgs e)
        {
            Form childForm = new Form();
            childForm.MdiParent = this;
            childForm.Text = "Window " + childFormNumber++;
            childForm.Show();
        }


        //public void FormSwitcher(int o)
        //{
        //    switch (o)
        //    {
        //        case 1:
        //            Console.WriteLine("*****Case 1");
        //            break;
        //        case 2:
        //            Console.WriteLine("*****Case 2");
        //            break;
        //        case 3:
        //            Console.WriteLine("*****Case 3");
        //            INV_office_form frm = (INV_office_form)OpenForm(typeof(INV_office_form));
        //            break;
        //        default:
        //            Console.WriteLine("*****Default case");
        //            break;
        //    }
        //}
        

        public Form OpenForm(Type t)
        {
            if (!t.IsSubclassOf(typeof(Form)) && !(t == typeof(Form))) throw new ArgumentException("Type is not a form", "t");
            List<Form> lst = new List<Form>();
            try
            {
                for (int i1 = 0; i1 < Application.OpenForms.Count; i1++)
                {
                    Form f = Application.OpenForms[i1];
                    if (f.IsMdiChild)
                        lst.Add(f);
                }
            }
            catch (IndexOutOfRangeException)
            {
                //This can change if they close/open a form while code is running. Just throw it away
            }
            while (lst.Count > 0)
            {
                Form f = lst[0];
                f.Close();
                f.Dispose();
                lst.RemoveAt(0);
            }
            Form result = (Form)Activator.CreateInstance(t);
            result.StartPosition = FormStartPosition.Manual;
            result.Left = 0;
            result.Top = 142;
            result.MdiParent = this;   
            result.Show();    
            return result;
        }


        private void MDIParent1_Load(object sender, EventArgs e)
        {
            //Create a new instance of the MDI child template form
            //INV_home_form dipForm = new INV_home_form();

            INV_home_form frm = (INV_home_form)OpenForm(typeof(INV_home_form));
            
            //Set parent form for the child window 
            //dipForm.MdiParent = this;

            //Display the child window
            //dipForm.Show();
            //dipForm.Left = 0;
            //dipForm.Top = 143;
            //dipForm.Size = ParentForm.ClientRectangle.Size;

            //dipForm.Height = this.Height;
            //dipForm.Width = this.Width;
        }

    }
}
